package com.aat.dxfy.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AspectUser {

	@Pointcut("execution(* com.aat.dxfy.spring.aop.UserService.say(..))")
	public void pcut() {
	}

	@Before("pcut()")
	public void before(JoinPoint jp) {
		System.out.println("睡前 脱衣服..");
		System.out.println(
				"log Ending method: " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName());
		Object[] args = jp.getArgs();
		for (int i = 0; i < args.length; i++) {
			System.out.println("args[" + i + "]:" + args[i]);
		}
	}

	@After("pcut()")
	public void after(JoinPoint jp) {
		System.out.println("睡后 穿衣服..");
		System.out.println(
				"log Begining method: " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName());
		Object[] args = jp.getArgs();
		for (int i = 0; i < args.length; i++) {
			System.out.println("args[" + i + "]:" + args[i]);
		}
	}

	@Around("pcut()")
	public Object around(ProceedingJoinPoint call) throws Throwable {
		String methodName = call.getSignature().getName();
		Object[] args = call.getArgs();
		// start
		System.out.println("around methodName:" + methodName);
		for (int i = 0; i < args.length; i++) {
			System.out.println("args[" + i + "]:" + args[i]);
		}

		// end
		return call.proceed();
	}

}
